package com.yogee.topseller.activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.yogee.core.http.loading.CustomProgressDialog;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.base.HttpActivity;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.LogUtils;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/3/18.
 */

public class ZxActivity extends HttpActivity {

    @BindView(R.id.add_card_titlelayout)
    TitleLayout titlelayout;
    @BindView(R.id.wb)
    WebView wb;
    @BindView(R.id.myProgressBar)
    ProgressBar bar;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_hyqx;
    }

    @Override
    protected void initView() {
        titlelayout.setActivity(this);
        titlelayout.setTitle(getIntent().getStringExtra("title"));
        wb.getSettings().setDomStorageEnabled(true);
        wb.getSettings().setDatabaseEnabled(true);
        wb.getSettings().setJavaScriptEnabled(true);
        wb.getSettings().setDefaultTextEncodingName("GBK");
        wb.getSettings().setAllowFileAccessFromFileURLs(false);
        wb.getSettings().setAllowUniversalAccessFromFileURLs(false);
        if (pd == null)
            pd = CustomProgressDialog.createDialog(this);
        wb.setWebViewClient(new WebViewClient());

        wb.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress == 100) {
                    bar.setVisibility(View.GONE);
                    if(pd!=null)
                        pd.dismiss();
                } else {
                    if (View.GONE == bar.getVisibility()) {
                        bar.setVisibility(View.VISIBLE);
                    }
                    bar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }
        });
        String weburl = getIntent().getStringExtra("weburl");
        LogUtils.e("sfz",weburl);
        wb.addJavascriptInterface(this, "nativeMethod");
        wb.loadUrl(weburl);
    }
}
